// ChatAppLayer.cpp: implementation of the CChatAppLayer class.
//
//////////////////////////////////////////////////////////////////////


#include "stdafx.h"
#include "ChatAppLayer.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CChatAppLayer::CChatAppLayer( char* pName ) 
	: CBaseLayer( pName ), 
	mp_Dlg( NULL )
{
	ResetHeader( ) ;
}

CChatAppLayer::~CChatAppLayer()
{

}



void CChatAppLayer::ResetHeader( )
{
	m_sHeader.app_length  = 0x0000 ;
	m_sHeader.app_type    = 0x00 ;
	memset( m_sHeader.app_data, 0, APP_DATA_SIZE ) ;
}



BOOL CChatAppLayer::Send(unsigned char *ppayload, int nlength)
{
	m_sHeader.app_length = (unsigned short) nlength ;
	memcpy(m_sHeader.app_data,ppayload,nlength > APP_DATA_SIZE ? APP_DATA_SIZE : nlength);


	BOOL bSuccess = mp_UnderLayer->Send( (unsigned char*)&m_sHeader, nlength + APP_HEADER_SIZE , 0x0820);


	return bSuccess ;
}

BOOL CChatAppLayer::Receive( unsigned char* ppayload )
{
	PCHAT_APP_HEADER app_hdr = (PCHAT_APP_HEADER) ppayload ;

	
		unsigned char GetBuff[APP_DATA_SIZE];
		memset(GetBuff, '\0', APP_DATA_SIZE);
		memcpy(GetBuff, app_hdr->app_data, app_hdr->app_length > 
			APP_DATA_SIZE ? APP_DATA_SIZE : app_hdr->app_length);
		
	

		mp_aUpperLayer[0]->Receive( (unsigned char*) GetBuff);

	
		return FALSE ;
}


